using HRMDataAccess;
using HRMDomain;
using NakedObjects.Boot;
using NakedObjects.Core.Context;
using NakedObjects.Core.NakedObjectsSystem;
using NakedObjects.EntityObjectStore;
using NakedObjects.Web.Mvc;
using NakedObjects.Web.Mvc.Helpers;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;

namespace HRMWeb.App_Start {
    public class RunWeb : RunMvc {
        protected override NakedObjectsContext Context {
            get { return HttpContextContext.CreateInstance(); }
        }

        protected override IServicesInstaller MenuServices {
            get {
                return new ServicesInstaller(
                    new LocationRepository(),
                    new EmployeeRepository(),
                    new AdminRepository());
            }
        }

        protected override IServicesInstaller ContributedActions {
            get { return new ServicesInstaller(); }
        }

        protected override IServicesInstaller SystemServices {
            get { return new ServicesInstaller(new SimpleEncryptDecrypt()); }
        }

        protected override IObjectPersistorInstaller Persistor
        {
            get
            {
                //Database.DefaultConnectionFactory = new SqlConnectionFactory();
                Database.SetInitializer(new DropCreateDatabaseWithSeed()); // Code First option
                var installer = new EntityPersistorInstaller();
                installer.AddCodeFirstDbContextConstructor(() => new HRMDataContext());  //Code First requirement: add each DbContext
                return installer;
            }
        }

        public static void Run() {
            new RunWeb().Start();
        }
    }
}